package com.qfedu.service.impl;

import com.qfedu.dao.IAddressDao;
import com.qfedu.dao.impl.AddressDaoImpl;
import com.qfedu.entity.Address;
import com.qfedu.entity.Result;
import com.qfedu.service.IAddressService;

import java.util.List;

public class AddressService implements IAddressService {
    private IAddressDao addressDao = new AddressDaoImpl();
    @Override
    public Result insertAddress(int uid, String name, String phone, String detail) {
        int i = addressDao.insertAddress(uid, name, phone, detail);
        if (i==0){
            return new Result("插入地址信息失败",false);
        }else {
            return new Result("插入地址信息成功",true);
        }
    }

    @Override
    public Result deleteAddress(int id) {
        int i = addressDao.deleteAddress(id);
        if (i==0){
            return new Result("删除地址信息失败",false);
        }else {
            return new Result("删除地址信息成功",true);
        }
    }

    @Override
    public Result updateAddress(int id, String name, String phone, String detail) {
        int i = addressDao.updateAddress(id, name, phone, detail);
        if (i==0){
            return new Result("修改地址信息失败",false);
        }else {
            return new Result("修改地址信息成功",true);
        }
    }

    @Override
    public Result queryAddress(int id) {
        Address address = addressDao.queryAddress(id);
        if (null==address){
            return new Result("查询单个地址信息失败",false,null);
        }else {
            return new Result("查询单个地址信息成功",true,address);
        }
    }

    @Override
    public Result queryAddressList(int uid) {
        List<Address> addressList = addressDao.queryAddressList(uid);
        if (addressList.size()==0){
            return new Result("查询所有地址信息失败",false,null);
        }else {
            return new Result("查询所有地址信息成功",true,addressList);
        }
    }

    @Override
    public Result setAddressOne(int id) {
        int i = addressDao.setAddressOne(id);
        if (i==0){
            return new Result("修改默认地址失败",false);
        }else {
            return new Result("修改默认地址成功",true);
        }
    }

    @Override
    public Result setAddressZero(int id) {
        int i = addressDao.setAddressZero(id);
        if (i==0){
            return new Result("移除默认地址失败",false);
        }else {
            return new Result("移除默认地址成功",true);
        }
    }

    @Override
    public Result queryDefaultAddress(int uid,int level) {
        int i = addressDao.queryDefaultAddress(uid,level);
        if (i==0){
            return new Result("移除默认地址失败",false);
        }else {
            return new Result("移除默认地址成功",true);
        }
    }
}
